package io.sage.modules.sys.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.sage.common.utils.R;
import io.sage.modules.sys.entity.SysRotationchart;
import io.sage.modules.sys.service.SysRotationchartService;
import io.swagger.annotations.Api;

/**
 * 轮播图管理
 * @author xujh
 *
 */
@RestController
@RequestMapping("/sys/sysrotationchart")
@Api(tags="轮播图管理接口")
public class SysRotationchartController {
	@Autowired
	private SysRotationchartService rotationchartService;
	
	/**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sysrotationchart:list")
    public R list(@RequestParam Map<String, Object> params){
    	
    	Integer pageSize = 1;
 		if (params != null && params.get("limit") != null) {
 			pageSize = java.lang.Integer.parseInt(params.get("limit").toString());
 		}
 		Integer pageNum = 10;
 		if (params != null && params.get("page") != null) {
 			pageNum = java.lang.Integer.parseInt(params.get("page").toString());
 		}

 		HashMap<String, Object> paramMap = new HashMap<String, Object>();
 		System.out.println(params.get("createName"));
 		if(params.get("createName")!=null){
 			
 			if(!"".equals(params.get("createName").toString())){
 				paramMap.put("createName", params.get("createName").toString());
 			}
 		}
 		
 		if(params.get("paperName")!=null){
 			if(!"".equals(params.get("paperName").toString())){
 				paramMap.put("paperName", params.get("paperName").toString());
 			}
 		}
 		if(params.get("deptNo")!=null){
 			if(!"".equals(params.get("deptNo").toString())){
 				paramMap.put("deptNo", params.get("deptNo").toString());
 			}
 		}

 		PageHelper.startPage(pageNum, pageSize);// 设置分页的起始码以及页面大小
 		
 		List<SysRotationchart> selectStudentLists = rotationchartService.selectRotationchart(params);
 		
 		PageInfo<SysRotationchart> rotationchart = new PageInfo<SysRotationchart>(selectStudentLists);// 传入list就可以了

 		return R.ok().put("rotationchart", rotationchart);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:sysrotationchart:info")
    public R info(@PathVariable("id") Integer id){
    	SysRotationchart sysRotationchart = rotationchartService.selectById(id);

        return R.ok().put("sysRotationchart", sysRotationchart);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:sysrotationchart:save")
    public R save(@RequestBody SysRotationchart sysRotationchart){
    	rotationchartService.insert(sysRotationchart);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:sysrotationchart:update")
    public R update(@RequestBody SysRotationchart sysRotationchart){
    	
    	rotationchartService.updateAllColumnById(sysRotationchart);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sysrotationchart:delete")
    public R delete(@RequestBody Integer[] ids){
    	rotationchartService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
